package viettravel.guiandevent.place;
import java.util.ArrayList;

import viettravel.DAO.RegionDAO;
import viettravel.common.Constants;
import viettravel.guiandevent.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class SpinnerRegionAdapter extends BaseAdapter implements SpinnerAdapter{

	private Context mContext;
	ArrayList<RegionDAO> mListRegion;
	
	public SpinnerRegionAdapter(Context context, ArrayList<RegionDAO> listRegion){
		mContext = context;
		mListRegion = listRegion;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListRegion.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mListRegion.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		RegionDAO regionDAO = mListRegion.get(position);
		View view = convertView;
		if(view == null){
			LayoutInflater layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = layoutInflater.inflate(R.layout.row_newplace_spinner, null);
		}
		TextView textView = (TextView)view.findViewById(R.id.spinnerText);
		textView.setTypeface(Constants.TYPEFACE_NYALA);
		textView.setText(regionDAO.getRegionName());
		return view;
	}
}
